<template>
    <div id="login">
        <div class="iconfont icon-guanbi1"></div>
        <h2>手机号注册</h2>
        <div class="line">
            <input type="text" placeholder="手机/用户名" v-model="userdata.phone">
        </div>
        <div class="line">
            <input type="password" placeholder="密码" v-model="userdata.pass">
        </div>
        <div class="btn line">
            <button @click="register">注册</button>
        </div>
        <div class="lastline">
            <span>手机号登录</span>
            <span>忘记密码</span>
        </div>
    </div>
</template>

<script lang="ts">
import { getRegisterData } from "@/api/register";
// interface IData {
//     userdata:string[]
// }
export default {
    data() {
        return {
            userdata: {
                phone: '',
                pass: '',
               
            }
        }
    },
    methods: {
        register() {
            if (/^1[3-9]\d{9}$/.test(this.userdata.phone) && this.userdata.pass) {
                getRegisterData(this.userdata).then((res) => {
                    console.log(res);
                    if (res.data.code == 200) {
                     
                        alert('注册成功')
                        //保存token到本地
                        localStorage.setItem('token', res.data.token)
                    } else {
                        alert('注册失败')
                    }
                })
            } else {
                alert('您输入的信息有误')
            }
        }
    }
}
</script>

<style lang='scss' scoped>
#login {
    padding: .1rem .3rem;

    h2 {
        width: 100%;
        font-size: .3rem;
        margin: .5rem 0 .2rem;
        font-weight: 700;
        align-items: center;
        text-align: center;

    }

    .line {
        input {
            font-size: 0.18rem;
            width: 100%;
            height: .6rem;
            border: .02rem solid rgb(223, 223, 223);
            padding-top: 10px;
            border-radius: 20px;
        }
    }

    button {
        width: 100%;
        height: .4rem;
        margin-top: .5rem;
        border-radius: .2rem;
        background-color: rgb(223, 223, 223);
        border: none;
        outline: none;
        color: rgb(171, 171, 171);
    }

    .lastline {
        color: rgb(63, 188, 243);
        display: flex;
        justify-content: space-between;
        margin-top: .1rem;
        font-size: .13rem;
    }
}
</style>